If --vcs flag specified, use vcs even if under an existing repo
authorCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Sun, 6 Sep 2015 19:52:13 +0000 (15:52 -0400)
committerCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Sun, 6 Sep 2015 19:52:13 +0000 (15:52 -0400)
Fixes #1210. If either `--vcs git` or `--vcs hg` is specified, assume
that means the user really wants the new project to use that VCS, even
if the project's location would be beneath an existing repository.

src/cargo/ops/cargo_new.rs
tests/test_cargo_new.rs

index c8b2fdca6d4c5d59b3a60118694a81db37974f6f..5b36097b394103e2c37186fcf13b7e9916e78cd5 100644 (file)
@@ -118,7 +118,7 @@ fn mk(config: &Config, path: &Path, name: &str,
     let vcs = match (opts.version_control, cfg.version_control, in_existing_vcs_repo) {
         (None, None, false) => VersionControl::Git,
         (None, Some(option), false) => option,
-        (Some(option), _, false) => option,
+        (Some(option), _, _) => option,
         (_, _, true) => VersionControl::NoVcs,
     };
 
index 981b75a32182c580f4f21373ac2ef59d597cc59f..398e07bec3f633bd4c38fee0c5b49babd643ae8e 100644 (file)
@@ -257,6 +257,23 @@ test!(subpackage_no_git {
                  is_not(existing_file()));
 });
 
+test!(subpackage_git_with_vcs_arg {
+    assert_that(cargo_process("new").arg("foo").env("USER", "foo"),
+                execs().with_status(0));
+
+    let subpackage = paths::root().join("foo").join("components");
+    fs::create_dir(&subpackage).unwrap();
+    assert_that(cargo_process("new").arg("foo/components/subcomponent")
+                                    .arg("--vcs").arg("git")
+                                    .env("USER", "foo"),
+                execs().with_status(0));
+
+    assert_that(&paths::root().join("foo/components/subcomponent/.git"),
+                 existing_dir());
+    assert_that(&paths::root().join("foo/components/subcomponent/.gitignore"),
+                 existing_file());
+});
+
 test!(unknown_flags {
     assert_that(cargo_process("new").arg("foo").arg("--flag"),
                 execs().with_status(1)